
import requests
import json
import utils
import config
import utils_longhu


#按天获取龙虎榜清单数据
def get_longhu_list_by_day(data_date):
    #1、取数
    #设置请求的头
    #请求东方财富获取数据
    #返回非标准json，预处理
    #headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"}
    headers = {
        'User-agent': "Mozilla 5.10",
        'cache-control': "no-cache",
        'postman-token': "220d2989-c111-fea3-874f-f5c31113db59"
    }
    url=config.getConfig()["url"]["longhu_list"]
    url_by_date = url.replace("yyyy-mm-dd", data_date)
    res = requests.get(url_by_date, headers=headers)
    ##result = res.text.split("jQuery112406326540387216384_1711515195823")[1].split("(")[1].split(");")[0]
    result = res.text
    result_json = json.loads(result)
    print(result_json)
    #2、存储到mysql
    #utils.save_quote_txn(result_json['data']['diff'])
    #print(result_json)
    #转成二维数组
    #longhu_list=utils.jsonlist2matrix(result_json['data']['items'])
    longhu_list=result_json['data']['items'];
    print(longhu_list)
    utils_longhu.save_longhu_list_by_date(longhu_list,data_date)
    #落表
    #utils.save_quote_txn_bath(result_value_matrix)

#get_longhu_list_by_day("2025-01-02")
